<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;
use Log;

class UserResource extends Resource
{
    public function toArray($request)
    {
        if(!empty($this->playerUser)){
            return [
                'id' => $this->id,
                'name' => $this->name,
                'email' => $this->email,
                'is_admin' => $this->is_admin,
                'head_image' => $this->head_image,
                'created_at' => $this->created_at->format('Y-m-d H:i:s'),
                'updated_at' => $this->updated_at,
                'last_login_at' => $this->last_login_at,
                'phone' => $this->phone,
                'league_id' => $this->playerUser->league_id,
                'cup_id' => $this->playerUser->cup_id,
                'realname' => $this->playerUser->realname,
                'age' => $this->playerUser->age,
                'number' => $this->playerUser->number,
                'height' => $this->playerUser->height,
                'weight' => $this->playerUser->weight,
                'strength' => $this->playerUser->strength,
                'level' => $this->playerUser->level,
                'site' => $this->playerUser->site,
                'join_season' => $this->playerUser->join_season,
                'join_date' => $this->playerUser->join_date,

                'balance' => $this->playerUser->balance,
                'league_total_time' => $this->playerUser->league_total_time,
                'join_total_time' => $this->playerUser->join_total_time,
                'attendance_rate' => $this->playerUser->attendance_rate,

                'league_total_game' => $this->playerUser->league_total_game,
                'join_game' => $this->playerUser->join_game,
                'goalkeeper_game' => $this->playerUser->goalkeeper_game,
                'referee_game' => $this->playerUser->referee_game,
                'win_game' => $this->playerUser->win_game,
                'win_rate' => $this->playerUser->win_rate,
                
                'goals' => $this->playerUser->goals,
                'assists' => $this->playerUser->assists,
                'champion_time' => $this->playerUser->champion_time,
                'award_time' => $this->playerUser->award_time,
                'down_time' => $this->playerUser->down_time,
                'ignore_time' => $this->playerUser->ignore_time,
            ];
        }else{
            return [
                'id' => $this->id,
                'name' => $this->name,
                'email' => $this->email,
                'is_admin' => $this->is_admin,
                'head_image' => $this->head_image,
                'created_at' => $this->created_at->format('Y-m-d H:i:s'),
                'updated_at' => $this->updated_at,
                'last_login_at' => $this->last_login_at,
                'phone' => $this->phone
            ];
        }
        
    }
}
